package com.kd.controller.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.kd.bean.admin.Notice_admin;
import com.kd.service.admin.INotice_adminService;

/**
 * 管理员<控制层> 公告
 * @author 	ZFC
 *
 */
@Controller
@RequestMapping("/notice_admin")
public class Notice_adminController {

	@Autowired
	private INotice_adminService adminService;
	
	@RequestMapping("/queryByNoticeWhereState")
	@ResponseBody
	public Map<String, Object> queryByNoticeWhereState(){
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			List<Notice_admin> list = adminService.queryByNoticeWhereState();
			map.put("list", list);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return map;
	}
	
	@RequestMapping("/queryAllNotice")
	@ResponseBody
	public PageInfo<Notice_admin> queryAllNotice(Integer pageNum,Integer pageSize){
		PageInfo<Notice_admin> info = null;
		try {
			info = adminService.queryAllNotice(pageNum, pageSize);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return info;
	}
	
	@RequestMapping("/queryByNotice_id")
	@ResponseBody
	public Notice_admin queryByNotice_id(Integer notice_id) {
		Notice_admin notice = null;
		try {
			notice = adminService.queryByNotice_id(notice_id);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return notice;
	}
	
	@RequestMapping("/removeNotice")
	@ResponseBody
	public Boolean removeNotice(Integer notice_id,Integer notice_state) {
		Boolean flag = false;
		try {
			flag = adminService.removeNotice(notice_id, notice_state);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}
	
	@RequestMapping("/insertNotice")
	public String insertNotice(Notice_admin notice,Model model) {
		try {
			Boolean flag = adminService.insertNotice(notice);
			String flagMsg= flag?"添加成功":"添加失败";
			model.addAttribute("msg", flagMsg);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "/view/admin/adminNotice.jsp";
	}
	
	@RequestMapping("/updateNotice")
	public String updateNotice(Notice_admin notice,Model model) {
		try {
			Boolean flag = adminService.updateNotice(notice);
			String flagMsg= flag?"修改成功":"修改失败";
			model.addAttribute("msg", flagMsg);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "/view/admin/adminNotice.jsp";
	}
}
